#include <bits/stdc++.h>
using namespace std;

int n;
int a[1000005];
vector<int> red, blue;
int ans;

void dfs(int d){
	if (d == n){
		int cnt = 0;
		for (size_t i = 1; i < red.size(); i++) if (red[i] == red[i-1]) cnt += red[i];
		for (size_t i = 1; i < blue.size(); i++) if (blue[i] == blue[i-1]) cnt += blue[i];
		ans = max(ans, cnt);
		return;
	}
	red.push_back(a[d]);
	dfs(d+1);
	red.pop_back();
	blue.push_back(a[d]);
	dfs(d+1);
	blue.pop_back();
}

void solve(){
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", a+i);
	ans = 0;
	dfs(0);
	printf("%d\n", ans);
}

int main(){
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	
	int T; scanf("%d", &T);
	while (T--) solve();
	return 0;
}
